package com.zsk;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

import com.zsk.config.CrossFilter;
import com.zsk.config.TokenFilter;

/**
 * main https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/2.0.9.RELEASE
 * 
 * @author keke
 * @date 2020/05/06
 */
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    /**
     * 配置跨域拦截器
     * 
     * @return
     */
    @Bean
    public FilterRegistrationBean<CrossFilter> corssFilterRegiste() {
        FilterRegistrationBean<CrossFilter> reFilter = new FilterRegistrationBean<>();
        // 创建并注册TestFilter
        reFilter.setFilter(new CrossFilter());
        // 拦截的路径（对所有请求拦截）
        reFilter.addUrlPatterns("/services/*");
        // 拦截器的名称
        reFilter.setName("CrossFilter");
        // 拦截器的执行顺序。数字越小越先执行
        reFilter.setOrder(1);
        return reFilter;
    }

    /**
     * 配置token拦截器
     * 
     * @return
     */
    @Bean
    public FilterRegistrationBean<TokenFilter> tokenFilterRegiste() {
        FilterRegistrationBean<TokenFilter> reFilter = new FilterRegistrationBean<>();
        reFilter.setFilter(new TokenFilter());
        reFilter.addUrlPatterns("/services/*");
        reFilter.setName("TokenFilter");
        reFilter.setOrder(4);
        return reFilter;
    }

}
